function fn() {
    axios
      .get('/my/userinfo', {
        // headers: {
        //   Authorization: localStorage.getItem('token')
        // }
      })
      .then(({ data: { data: { email, id, nickname, user_pic, username }, status, message, } }) => {
        // console.log(data)
        if (status === 1 && message === '身份认证失败！') {
          location.href = './login.html'
        }
        // uesr_pic, id, username, nickname, email, message, status 
        // 处理昵称 默认值是用户名
        let name = nickname || username
        // console.log(name)
        // 处理头像
        if (user_pic) {
          // 图片头像隐藏
          $('.avatar').attr('src', user_pic).show()
          // 文字头像隐藏
          $('.text-avatar-box').hide()
        } else {
          // 图片头像隐藏
          $('.avatar').hide()
          // 文字头像显示
          $('.text-avatar-box').show()
          $('.text-avatar').text(name[0].toUpperCase())
        }
        $('#welcome').text('欢迎' + name)
      })
  
  
  }
  
  fn()
  // 退出功能
  $('#btnLogout').on('click', function () {
    var layer = layui.layer;
  
    layer.confirm('确定要退出登录吗?', { icon: 3, title: '提示' }, function (index) {
      layer.close(index);
      //do something
      //  1.清除token
      localStorage.removeItem('token')
      //  2.跳转页面
      location.href = '/login.html'
  
    });
  
  }) 